<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace app\user\controller;

use cmf\controller\HomeBaseController;
use think\Validate;

class SendMessageController extends HomeBaseController
{
    //python send网站提示短信---python跑在COD服务器上
    public function pythonSend()
    {
        if ($this->request->isPost()) {
            $data = input('post.');
            if ($data['type'] == 'python' && $data['name'] == 'NGE') {
                //处理链接

                 if(strstr($data['text'],'facebook')){
                    //粉丝页链接
                    $a = explode('/', $data['text']);
                    foreach ($a as $key => $value) {
                        if (strstr($value,'-')) {
                            $url = $value;
                            $msg = '您的主页'.$url.'已不能访问，请及时查看。';
                        }
                    }
                 }else{
                    //域名
                    $a = explode('/', $data['text']);
                    foreach ($a as $key => $value) {
                        if (strstr($value,'.')) {
                            $url = trim(strrev(strstr(strrev(trim($value,'www.')), '.')),'.');
                            $msg = '您的网站'.$url.'已不能访问，请及时查看。';
                        }
                    }
                 }

                // $msg = '您的网站 '.$url.' 已不能访问，请及时查看。';
                $mobile = trim($data['phone']);

                $param  = ['mobile' => $mobile, 'code' => $msg];
                $result = hook_one("send_mobile_verification_code", $param);

                if ($result !== false && !empty($result['error'])) {
                    $message['message'] = $result['message'];
                    $message['status'] = false;
                    echo json_encode($message);die;
                }

                // if ($result === false) {
                //     $this->error('未安装验证码发送插件,请联系管理员!');
                // }

                if (!empty($result['message'])) {
                    $message['message'] = $result['message'];
                    $message['status'] = false;
                    echo json_encode($message);die;
                } else {
                    $message['message'] = '短信发送成功';
                    $message['status'] = true;
                    echo json_encode($message);die;
                }

            }else{
                $message['message'] = '参数错误';
                $message['status'] = false;
                echo json_encode($message);die;
            }
        }		

    }

}